package com.smm.web.vmc.controller.User;

import com.smm.web.vmc.domain.Camera;
import com.smm.web.vmc.domain.Receipt;
import com.smm.web.vmc.domain.User;
import com.smm.web.vmc.dto.ReceiptDto;
import com.smm.web.vmc.service.CameraService;
import com.smm.web.vmc.service.ReceiptService;
import com.smm.web.vmc.service.UserService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * Created by zhenghao on 2016/8/31.
 *
 */
@Controller
@RequestMapping("/home/vdio")
public class VdioController {

    @Resource
    private ReceiptService receiptService;


    @Resource
    private CameraService cameraService;


    @RequestMapping("/list.do")
    public ModelAndView list(HttpServletRequest request){

        //从session中获取用户信息
        User user = (User) request.getSession().getAttribute(UserService.USER_SESSION_KEY);

        //通过用户与仓单的关联关系，获取当前用户的仓单列表
        List<ReceiptDto> receipts = receiptService.getAllByUser(user.getId());

//        logger.info("----------------receipts:"+receipts);

        //传递数据到页面
        ModelAndView mv = new ModelAndView("vdioList");

        mv.addObject("receipts",receipts);

        return mv;
    }



    @RequestMapping("/info.do")
    public ModelAndView info(String repNo,int cameraId){

        ModelAndView mv = new ModelAndView("vdioInfo");

        //获取指定摄像头信息
        Camera camera = cameraService.getOneById(cameraId);

        //获取指定仓单信息
        Receipt receipt = receiptService.getOneById(repNo);

        //通过仓单编号获取所有关联摄像头列表
        List<Camera> cameraList = cameraService.getAllByReceipt(repNo);

        //传递数据
        mv.addObject("camera",camera);
        mv.addObject("receipt",receipt);
        mv.addObject("cameraList",cameraList);

        return mv;
    }


}
